8. HTTP

HTTP (HyperText Transfer Protocol) Protocol

It's a simple protocol originally designed to retrieve static web pages.
It is used to communicate and transfer data over the web. It defines how messages are formatted and transmitted by browser.
It is connection-less (because once a single HTTP request is serviced, the connection is closed and not reused), but uses TCP as its transport mechanism.
TCP Port 80 or 8080
HTTP functions as a request–response protocol in the client–server computing model.
A client (browser) sends an HTTP request to the server; then the server returns a status line, such as "HTTP/1.1 200 OK", and a message of its own.
The response contains status information about the request and may also contain the requested content.

7709862b662fe7664786775bcce6b41e.png

HTTP Versions: 1.1,2.0,3.0

HTTPS (Hypertext Transfer Protocol Secure) , TCP Port 443
In HTTPS HTTP is encrypted using TLS (Transport Layer Security) or SSL (Secure Sockets Layer). The protocol is therefore also referred to as HTTP over TLS, or HTTP over SSL.

HTTP Requests

All HTTP messages contain:

  1. One or more headers
  2. Then a blank line
  3. An optional Message Body

First line of the HTTP requests has three elements

  1. A verb (action word) indicating the HTTP method
  2. The requested URL
  3. The HTTP version used

16b14d6d97b48a163abffcf98f54e799.png

HTTP Responses

The typical HTTP request consists of three items:

  1. The HTTP version
  2. The numeric status code.
  3. The text describing the status response.

5e83bf7ceee878d9aef5c9310e53e85c.png

Status Codes

Every HTTP response must contain a status-code indicating the the result of the request. There are five groups of status codes based upon the first digit of the code:

Common HTTP status codes include:

b9a9256efb3799b31c5c2868707e3245.png

HTTP Methods (verbs)

HTTP defines a set of request methods to indicate the desired action to be performed for a given resource.

GET /index.html?param=value HTTP/1.0

POST /test/demo_form.php HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2

Most common methods are GET and POST.

URL's

The uniform resource locator (URL) is a unique ID for every web resource for which a resource can be retrieved.
The basic syntax of the URL is:

protocol://hostname[:port]/ [/path/] file [?param=value]

The port number is optional and only necessary if the port is different from the default port used by the specified protocol

URI vs URL

URI stands for uniform resource identifier and URL stands for uniform resource locator.
A URI is an identifier of a specific resource. Like a page, or book, or a document.
A URL is special type of identifier that also tells you how to access it, such as HTTPs, FTP, etc.

04ab2abaacfb85ff26726ccb887f3bed.png

URI's must start with a scheme (e.g. file, http, ftp)
A scheme may or may not be associated with a protocol.
For instance the schemes 'http' and 'ftp' are clearly associated with the HTTP and FTP protocols, whereas the 'file' scheme is not associated with any protocol.